
$(function(){
    ajaxUserHtml("");
});

var ajaxUserHtml = function(deptId,typez){
    var urlz = "";;
    //单位
    if(typez == 0){
        urlz =  "/sys/dept/commonDept?deptId="+deptId;
    }else{
        urlz =  "/sys/dept/commonDept?qylbId="+deptId;
    }
    $.ajax({
        url : urlz,
        type : "get",
        dataType : "html",
        success : function(r) {
            $("#deptChild").html(r);
        }
    });
};

var setting = {
    showLine : true,
    view: {
        selectedMulti: false,
        showTitle : true
    },
    data: {
        simpleData: {
            enable : true,
            idKey : "id",		// 结点的id,对应到Json中的id
            pIdKey : "pId"     // 结点的pId,对应到Json中的pId
        },
        key: {
            title: "title"
        }
    },
    callback : {
        onClick : showDetail			// 	点击节点时，显示节点详细信息
    }

};

$(document).ready(function(){
    cshData();
});


var cshData = function(){
    $.ajax({
        async : false,
        cache:false,
        type: 'POST',
        dataType : "json",
        url: "/sys/dept/zTreeHangYe",
        error: function () {//请求失败处理函数
            alert('请求失败');
        },
        success:function(data){ //请求成功后处理函数。
            //把后台封装好的简单Json格式赋给treeNodes
            $.fn.zTree.init($("#departtree"), setting,eval(data));
            //fuzzySearch('departtree','#keyword',null,true); //初始化模糊搜索方法
        }
    });
};

function showDetail(event, treeId, treeNode, clickFlag){
    var detpId = treeNode.id;
    var typez = treeNode.typez;
    ajaxUserHtml(detpId,typez);
}


function refreahTree(){
    var treeObjz = $.fn.zTree.getZTreeObj("departtree");
    treeObjz.refresh();
    cshData();
}
